package cn.zcf.basic.service.impl;

import cn.zcf.basic.mapper.BaseMapper;
import cn.zcf.basic.query.BaseQuery;
import cn.zcf.basic.service.IBaseService;
import cn.zcf.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;
    @Override
    public List<T> loadAll() {
        return mapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        mapper.remove(id);
    }

    @Override
    @Transactional
    public void add(T T) {
        mapper.add(T);
    }

    @Override
    @Transactional
    public void update(T T) {
        mapper.update(T);
    }

    @Override
    public PageList<T> pageQuery(BaseQuery query) {
        return new PageList<T>(mapper.queryCount(query),mapper.queryData(query));
    }

    @Override
    @Transactional
    public void patchDel(List<Long> ids) {
        mapper.patchDel(ids);
    }
}
